<template>
  <div class="borrowbook_container">
    <div class="header"><p>查询图书情况</p></div>
    <div class="banner">
      <div class="book_number">
        <el-input
          placeholder="请输入图书编号"
          v-model="data.bookNumber"
          style="height: 40px; width: 300px"
        ></el-input>
      </div>
      <div class="query_button">
        <el-button type="warning" @click="goExpire" size="large">查询</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, reactive } from "vue";
import { getReturn, getQueryBook } from "../../api/api";
import { useRouter } from "vue-router";
const router = useRouter();

const data = reactive({
  bookNumber: "",
});

const goExpire = async () => {
  // 发送axios请求，携带图书编号  如果返回状态码为成功 跳转逾期的页面 否则提示未借出图书
  getQueryBook(data)
    .then(res => {
      console.log(res.data, "111");
      ElMessage({
        message: "图书借出",
        type: "success",
      });
      router.push({ name: "BookMessage", params: { bookId: data.bookNumber } });
    })
    .catch(err => {
      console.log(err, "err");
      ElMessage.error("图书未借出或者输入错误");
    });
};
</script>

<style lang="less" scoped>
.borrowbook_container {
  display: flex;
  flex-direction: column;
  align-items: center;
  .header {
    width: 100%;
    height: 100px;
    // background-color: pink;
    p {
      color: black;
      font-size: 30px;
      text-align: center;
      line-height: 60px;
    }
  }
  .banner {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 60%;
    height: 400px;
    // background-color: brown;
    div {
      margin-top: 15px;
      // margin-left: ;
    }
    .borrow_date {
      margin-left: 8px;
    }
    .query_button {
      margin-top: 30px;
    }
  }
}
</style>
